/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor. 112*82
 * base: 48*48
 * lanceStand: 64*64
 * lanceAttack: 76*32
 * Hmax: 82
 * Wmax: 188 
 */

var CHAR= {
    buffer: "",
    ctx:"",
    size: 48,
    pos: {
        X: WIDTH/2 ,
        Y: 0
    },
    move: {
        left: false,
        right: false,
        jump: false,
    },
    isRight:true,
    sprite: "",
    lance: "",
    attack: "",
    isAttacking: false,
    isAttacked: false,
    atkRelease: true,
    i: 0,
    hp: 100,
    
    Init: function() {
        this.buffer = document.createElement('canvas');
        this.buffer.height=82;
        this.buffer.width=188;
        
        this.ctx=this.buffer.getContext("2d");
        
        this.sprite = new Image();
        this.sprite.src = "RES/OrbMonolyth.png";
        
        this.lance = new Image();
        this.lance.src = "RES/Lance.png"
        
        this.attack = new Image();
        this.attack.src = "RES/LanceA.png"
    },
    
    Draw: function(ctx) {
        this.ctx.clearRect(0,0,this.buffer.width,this.buffer.height);
        
        if (!this.isRight) {
            this.ctx.save();
            this.ctx.translate(this.buffer.width, 0);
            this.ctx.scale(-1,1);
        }
        
        this.ctx.drawImage(this.sprite, 112 - this.size, this.buffer.height - this.size);
        this.isAttacking? this.ctx.drawImage(this.attack, 100,42) : this.ctx.drawImage(this.lance, 12, 12);
        this.ctx.restore();
        
        ctx.drawImage(this.buffer, this.pos.X - 88, HEIGHT - FLOOR - this.buffer.height - this.pos.Y);
    },
    
    Update: function() {
        if (this.move.left && !CHAR.isAttacked) {
            this.isRight=false;
            this.pos.X -= WALKSPEED;
        }
        
        if (this.move.right && !CHAR.isAttacked) {
            this.isRight=true;
            this.pos.X += WALKSPEED;
        }
        
        if (this.isAttacking) {
            this.i<8? this.i++ : (this.i=0, this.isAttacking=false);
            this.pos.X += (this.isRight?2:-2);
        }
    }
};